#include "StomperLib/Export/Exporter.h"

namespace StomperLib
{
namespace Export
{
Exporter::Exporter( )
{
}

Exporter::~Exporter( )
{
}

int Exporter::Export( StompedReality::Utility::FileSystem* fileSystem, Json::Value& rootNode, ExportItemList* itemList,
                      std::function<bool(StomperLib::Export::ExportItem*)> itemFilter )
{
  int exportCount = 0;

  for (auto exportItem = itemList->begin( ); exportItem != itemList->end( ); ++exportItem)
  {
    if ( !itemFilter( *exportItem ) )
      continue;

    if (!(*exportItem)->IsExportable( fileSystem ))
      continue;

    rootNode.append((*exportItem)->ExportData( fileSystem ));
    exportCount++;
  }

  return exportCount;
}

int Exporter::Export( StompedReality::Utility::FileSystem* fileSystem, Json::Value& rootNode, ExportItemMap* itemList,
                      std::function<bool(StomperLib::Export::ExportItem*)> itemFilter )
{
  int exportCount = 0;

  for (auto exportItemPair = itemList->begin( ); exportItemPair != itemList->end( ); ++exportItemPair)
  {
    if ( !itemFilter( exportItemPair->second ) )
      continue;

    if (!exportItemPair->second->IsExportable( fileSystem ))
      continue;

    rootNode.append( exportItemPair->second->ExportData( fileSystem ));
    exportCount++;
  }

  return exportCount;
}

}
}